/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.media.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.hk.media.entity.HkMediaSystemCategory;
import com.thinkgem.jeesite.modules.hk.media.service.HkMediaSystemCategoryService;

/**
 * 自媒体系统推荐分类Controller
 * @author 罗天文
 * @version 2018-05-24
 */
@Controller
@RequestMapping(value = "${adminPath}/media/hkMediaSystemCategory")
public class HkMediaSystemCategoryController extends BaseController {

	@Autowired
	private HkMediaSystemCategoryService hkMediaSystemCategoryService;
	
	@ModelAttribute
	public HkMediaSystemCategory get(@RequestParam(required=false) String id) {
		HkMediaSystemCategory entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = hkMediaSystemCategoryService.get(id);
		}
		if (entity == null){
			entity = new HkMediaSystemCategory();
		}
		return entity;
	}
	
	@RequiresPermissions("media:hkMediaSystemCategory:view")
	@RequestMapping(value = {"list", ""})
	public String list(HkMediaSystemCategory hkMediaSystemCategory, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<HkMediaSystemCategory> page = hkMediaSystemCategoryService.findPage(new Page<HkMediaSystemCategory>(request, response), hkMediaSystemCategory); 
		model.addAttribute("page", page);
		return "hk/media/hkMediaSystemCategoryList";
	}

	@RequiresPermissions("media:hkMediaSystemCategory:view")
	@RequestMapping(value = "form")
	public String form(HkMediaSystemCategory hkMediaSystemCategory, Model model) {
		model.addAttribute("hkMediaSystemCategory", hkMediaSystemCategory);
		return "hk/media/hkMediaSystemCategoryForm";
	}

	@RequiresPermissions("media:hkMediaSystemCategory:edit")
	@RequestMapping(value = "save")
	public String save(HkMediaSystemCategory hkMediaSystemCategory, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, hkMediaSystemCategory)){
			return form(hkMediaSystemCategory, model);
		}
		hkMediaSystemCategoryService.save(hkMediaSystemCategory);
		addMessage(redirectAttributes, "保存自媒体系统推荐分类成功");
		return "redirect:"+Global.getAdminPath()+"/media/hkMediaSystemCategory/?repage";
	}
	
	@RequiresPermissions("media:hkMediaSystemCategory:edit")
	@RequestMapping(value = "delete")
	public String delete(HkMediaSystemCategory hkMediaSystemCategory, RedirectAttributes redirectAttributes) {
		hkMediaSystemCategoryService.delete(hkMediaSystemCategory);
		addMessage(redirectAttributes, "删除自媒体系统推荐分类成功");
		return "redirect:"+Global.getAdminPath()+"/media/hkMediaSystemCategory/?repage";
	}

}